package cn.itcast.bos.service.promotion.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.promotion.PromotionRepository;
import cn.itcast.bos.domain.take_delivery.PageBean;
import cn.itcast.bos.domain.take_delivery.Promotion;
import cn.itcast.bos.service.promotion.PromotionService;
@Service
@Transactional
public class promotionServiceImpl implements PromotionService {
	@Autowired
	private PromotionRepository promotionRepository;
	@Override
	public void save(Promotion model) {
		promotionRepository.save(model);
	}
	@Override
	public Page<Promotion> findpageData(Pageable pageable) {
		return promotionRepository.findAll(pageable);
	}
	@Override
	public PageBean<Promotion> findPageData(Integer page, Integer rows) {
		Pageable pageable = new  PageRequest(page-1, rows);
		Page<Promotion> pageData = promotionRepository.findAll(pageable);
		PageBean<Promotion> pageBean = new PageBean<Promotion>();
		pageBean.setContent(pageData.getContent());
		pageBean.setTotalElements(pageData.getTotalElements());
		return pageBean;
	}
	/**
	 * 定时器
	 */
	@Override
	public void updatastart(Date date) {
		promotionRepository.updatestart(date);
	}

}
